package com.wanxi.chat.service.impl;

import com.wanxi.chat.model.ChatEntity;
import com.wanxi.chat.offline.api.OfflineFeignClient;
import com.wanxi.chat.result.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

@RestController
@Component
public class OffLineMessageServiceImpl implements OfflineFeignClient {
    @Autowired
    private  RedisTemplate redisTemplate;

    @PostMapping("/save")
    @ResponseBody
    @Override
    public CommonResult redisSaveFeign(@RequestBody ChatEntity chatQueryVO) {
        ValueOperations<Long,ChatEntity> valueOperations=redisTemplate.opsForValue();
        valueOperations.set(chatQueryVO.Id,chatQueryVO);
        return CommonResult.success("存储成功");
    }
    @RequestMapping("/pull")
    @ResponseBody
    @Override
    public CommonResult redisPullFeign(@RequestBody ChatEntity chatQueryVO) {
        ValueOperations<Long,ChatEntity> valueOperations=redisTemplate.opsForValue();
        ChatEntity entity = valueOperations.get(chatQueryVO.Id);
        return  CommonResult.success(entity);
    }
    @PostMapping("/remove")
    @ResponseBody
    @Override
    public CommonResult redisRemoveFeign(@RequestBody ChatEntity chatQueryVO) {
        Boolean delete = redisTemplate.delete(chatQueryVO.Id);
        return  CommonResult.success(delete);
    }
}
